package com.chat.business.controller;

import com.chat.common.dto.SendFriendApplyDto;
import com.chat.common.dto.ProcessApplyDto;
import com.chat.business.service.IApplyService;
import com.chat.business.service.IMessageChannelMappingService;
import com.chat.common.vo.R;
import com.chat.common.vo.SearchChannelMappingVO;
import com.chat.common.vo.UserVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息频道/好友
 * @author wei kunJie
 * @date 2024/3/30 14:09:39
 */
@RestController
@RequestMapping("/business/channel/friend")
public class FriendsChannelMappingController {
    @Resource
    private IApplyService applyService;
    @Resource
    private IMessageChannelMappingService channelMappingService;
    /**
     * 获取所有的好友
     * 根据用户id（从token中）获取所有的好友
     */
    @GetMapping("/getAllFriends")
    public R<List<UserVo>> getAllFriends(){
        return channelMappingService.getAllFriends();
    }

    /**
     * 根据账号获取好友信息
     * @param account
     * @return
     */
    @GetMapping("/getFriendByAccount")
    public R<UserVo> getFriendByAccount(@RequestParam("account") String account){
        return channelMappingService.getFriendByAccount(account);
    }

    /**
     * 添加好友，发送好友申请
     * 传入要添加的好友的账号、验证信息进行添加
     * @return
     */
    @PostMapping("/addFriend")
    public R sendFriendApply(@RequestBody SendFriendApplyDto sendFriendApplyDto){
        return applyService.sendFriendApply(sendFriendApplyDto);
    }

    /**
     * 删除好友
     * 传入要删除好友的账号
     * @return
     */
    @PostMapping("/removeFriend")
    public R removeFriend(@RequestParam String userAccount){
        return channelMappingService.removeFriend(userAccount);
    }

    /**
     *处理好友申请
     * @return
     */
    @PostMapping("/processFriendRequest")
    public R processFriendApply(@RequestBody ProcessApplyDto processApplyDto){
        return applyService.processFriendApply(processApplyDto);
    }

    /**
     * 全网查询好友或群
     * @param keyword
     * @return
     */
    @GetMapping("/searchChannelMapping")
    public R<List<SearchChannelMappingVO>> searchChannelMapping(@RequestParam("keyword") String keyword){
        return channelMappingService.searchChannelMapping(keyword);
    }

}
